package com.alibaba.yinan.domain.task.service.strategy;

import com.alibaba.yinan.domain.task.enums.TaskType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName TaskStrategySelector
 * @Author mengke
 * @create 2025/8/3 22:14
 * @Description
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskStrategySelector {

    private final List<TaskTypeStrategy> strategies;

    public TaskTypeStrategy select(TaskType type) {
        return strategies.stream()
                .filter(s -> s.support(type))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("不支持的任务类型：" + type));
    }
}
